package ru.amse.baltijsky.javascheme.tree;

/**
 * Types of language constructs that may appear in our internal tree.
 */
public enum NodeType {
    ACTION(ActionNode.class),
    BLOCK(BlockNode.class),
    IF(IfNode.class),
    SWITCH(SwitchNode.class),
    FOR(ForNode.class),
    WHILE(WhileNode.class),
    DO_WHILE(DoWhileNode.class),
    BREAK(BreakNode.class),
    CONTINUE(ContinueNode.class),
    RETURN(ReturnNode.class),
    THROW(ThrowNode.class),
    SYNCHRONIZED(SynchronizedNode.class),
    TRY(TryNode.class),
    CATCH(CatchNode.class),
    FINALLY(FinallyNode.class),
    UNIT_BLOCK(UnitBlockNode.class),
    CLASS(ClassNode.class),
    METHOD(MethodNode.class),
    TRANSLATION_UNIT(TranslationUnitNode.class);

    public static final int NODE_TYPES_AMOUNT = values().length;

    private final Class<? extends SchemaNode> nodeClass;

    public Class<? extends SchemaNode> getNodeClass() {
        return nodeClass;
    }

    NodeType(Class<? extends SchemaNode> nodeClass) {
        this.nodeClass = nodeClass;
    }

    public static NodeType getNodeType(String s) throws IllegalArgumentException {
        for (NodeType t : values()) {
            if (s.equals(t.name().toLowerCase())) {
                return t;
            }
        }
        throw new IllegalArgumentException("Unknown node type.");
    }

    public String getDescription() {
        return this.name().toLowerCase();
    }

    public int toInt() {
        return this.ordinal();
    }
}
